class Admin::AdminUsersController < AdminController
  def index
    @admin_users = AdminUser.filter(params).paginate :page => params[:page], :per_page => 30
  end
  
  def show
    @admin_user = AdminUser.find(params[:id])
  end
  
  def new
    @admin_user = AdminUser.new
  end
  
  def create
    @admin_user = AdminUser.new(params[:admin_user])
    if @admin_user.save
      flash[:notice] = "Successfully created admin user."
      redirect_to params[:save_and_new].blank? ? [:admin, @admin_user] : new_admin_admin_user_path
    else
      render 'new'
    end
  end
  
  def edit
    @admin_user = AdminUser.find(params[:id])
  end
  
  def update
    @admin_user = AdminUser.find(params[:id])
    if params[:admin_user][:password].blank?
      flash[:notice] = "Successfully updated admin user."
      params[:admin_user].delete(:password)
      @admin_user.update_attributes(params[:admin_user])
      redirect_to params[:save_and_new].blank? ? [:admin, @admin_user] : new_admin_admin_user_path
    elsif @admin_user.update_attributes(params[:admin_user])
      flash[:notice] = "Successfully updated admin user."
      redirect_to params[:save_and_new].blank? ? [:admin, @admin_user] : new_admin_admin_user_path
    else
      render 'edit'
    end
  end
  
  def destroy
    @admin_user = AdminUser.find(params[:id])
    @admin_user.del
    flash[:notice] = "Successfully destroyed admin user."
    redirect_to admin_admin_users_url
  end
end
